﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.Utils;
using System.Collections.Generic;
using Ccit.OA.MsSystemDoc; 

namespace Ccit.OA.SystemDoc
{
    public class SystemDocBLL
    {
        private ISystemDoc iSystemDoc = null;
         public SystemDocBLL()
        {
            iSystemDoc = (ISystemDoc)Factory.CreateObject("Ccit.OA.SystemDoc.dll", "Ccit.OA.SystemDoc.SystemDoc",
                                                ImportComponentType.DotNetDll, null);
        }
         #region 系统文档         
        /// <summary>
        /// 获取类别树根节点名称
        /// </summary>
        /// <param name="sClassType"></param>
        /// <returns></returns>
         public string GetSysDocNode(string sClassType, string swhereClause)
         {
             string NodeName = iSystemDoc.GetSysDocNode(sClassType,swhereClause);
             //iSystemDoc = null;
             return NodeName;
         }
        /// <summary>
        /// 获取菜单树信息
        /// </summary>
        /// <returns></returns>
         public string GetSysDocNodes(string sClassType, string swhereClause)
         {
             string Nodes = iSystemDoc.GetSysDocNodes(sClassType, swhereClause);
             iSystemDoc = null;
             return Nodes;
         }
        /// <summary>
        /// 获取菜单树子节点信息
        /// </summary>
        /// <param name="SysDocId"></param>
        /// <returns></returns>
         public List<MsSecondClass> GetSysDocNodesXML(string SysDocId, string sClassType, string swhereClause)
         {
             List<MsSecondClass> lstSec = iSystemDoc.GetSysDocNodesXML(SysDocId, sClassType, swhereClause);
             iSystemDoc = null;
             return lstSec;
         }
         /// <summary>
        /// 删除节点信息
        /// </summary>
        /// <param name="SysDocId"></param>
        /// <returns></returns>
         public List<string> DeleteSysDocMess(string SysDocId)
         {
             List<string> lstResult = iSystemDoc.DeleteSysDocMess(SysDocId);
             iSystemDoc = null;
             return lstResult;
         }
         /// <summary>
        /// 获取编辑页面的上级栏目信息
        /// </summary>
        /// <param name="filterSysDocId"></param>
        /// <param name="sClassType"></param>
        /// <returns></returns> 
         public List<DictLib> GetAllSysDocMess(string sClassType, string filterSysDocId, bool bAllowHeader, string headerText, string headerValue)
         {
             List<DictLib> lstDict = iSystemDoc.GetAllSysDocMess(filterSysDocId, sClassType);

             if (bAllowHeader)
             {
                 DictLib dict;
                 dict = new DictLib(headerText, headerValue);
                 lstDict.Insert(0, dict);
             }
             return lstDict;
         }
         public string getAddrLayCodeById(string filterAddrId)
         {
             string iNum = iSystemDoc.getAddrLayCodeById(filterAddrId);
             return iNum;
         }
         public string GetNodeId(string systemId)
         {
             string iNum = iSystemDoc.GetNodeId(systemId);
             return iNum;
         }
         /// <summary>
        /// 保存系统类别信息
        /// </summary>
        /// <param name="ms"></param>
        /// <returns></returns>
         public List<string> DoSaveSysDocMess(MsSecondClass ms)
         {
             List<string> lstResult = iSystemDoc.DoSaveSysDocMess(ms);
             iSystemDoc = null;
             return lstResult;
         }
        /// <summary>
        /// 保存成功之后添加树节点信息
        /// </summary>
        /// <param name="NodeId"></param>
        /// <returns></returns>
         public string GetNodeLevelStruct(string NodeId)
         {
             string NodeLeve = iSystemDoc.GetNodeLevelStruct(NodeId);
             iSystemDoc = null;
             return NodeLeve;
         } 
        /// <summary>
        /// 获取编辑页面信息
        /// </summary>
        /// <param name="SysDocId"></param>
        /// <param name="sClassType"></param>
        /// <returns></returns>
         public MsSecondClass GetSecondClassMess(string SysDocId, string sClassType)
         {
             MsSecondClass Ms = iSystemDoc.GetSecondClassMess(SysDocId, sClassType);
             iSystemDoc = null;
             return Ms;
         }
        /// <summary>
        /// 获取编号规则页面树节点名称
        /// </summary>
        /// <param name="sClassType"></param>
        /// <returns></returns>
         public List<MsCodeRule> GetCodeRuleNodes(string sClassType)
         {
             List<MsCodeRule> lstMs = iSystemDoc.GetCodeRuleNodes(sClassType);
             iSystemDoc = null;
             return lstMs;
         }
         public string GetSysDocId(string sNumber, string sClassType)
         {
             string iDocId = iSystemDoc.GetSysDocId(sNumber, sClassType);
             return iDocId;
         }
         /// <summary>
        /// 保存编号规则信息
        /// </summary>
        /// <param name="ms"></param>
        /// <returns></returns>
         public List<string> DoSaveCodeRuleMes(MsCodeRule ms)
         {
             List<string> lstResult = iSystemDoc.DoSaveCodeRuleMes(ms);
             iSystemDoc = null;
             return lstResult;
         }
        /// <summary>
        /// 删除规则信息
        /// </summary>
        /// <param name="codeId"></param>
        /// <returns></returns>
         public List<string> DoOperateCodeRule(string codeId)
         {
             List<string> lstResult = iSystemDoc.DoOperateCodeRule(codeId);
             iSystemDoc = null;
             return lstResult;
         }
        /// <summary>
        /// 获取规则名称信息
        /// </summary>
        /// <param name="codeId"></param>
        /// <returns></returns>
         public MsCodeRule GetCodeRule(string codeId)
         {
             MsCodeRule ms = iSystemDoc.GetCodeRule(codeId);
             //iSystemDoc = null;
             return ms;
         }
        /// <summary>
        /// 获取规则明细信息
        /// </summary>
        /// <param name="codeId"></param>
        /// <returns></returns>
         public List<MsCodeRuleDetail> GetCodeRuleDetailMes(string codeId)
         {
             List<MsCodeRuleDetail> lstDetail = iSystemDoc.GetCodeRuleDetailMes(codeId);
             iSystemDoc = null;
             return lstDetail;
         }
          /// <summary>
        /// 获取树第一层节点信息
        /// </summary>
        /// <param name="sClassType"></param>
        /// <returns></returns>
         public string GetCodeRuleNodesMes(string sClassType)
         {
             string sXML = iSystemDoc.GetCodeRuleNodesMes(sClassType);
             //iSystemDoc = null;
             return sXML;
         }
        /// <summary>
        /// 获取文档编码规则表信息
        /// </summary>
        /// <param name="sNumber"></param>
        /// <returns></returns>
         public DataSet GetCodeManage(string codeId, string sNumber)
         {
             DataSet dSet = iSystemDoc.GetCodeManage(codeId, sNumber);
             iSystemDoc = null;
             return dSet;
         }
        /// <summary>
        /// 删除文档编码规则表信息(doc_b8)
        /// </summary>
        /// <param name="Number"></param>
        /// <param name="codeId"></param>
        /// <returns></returns>
         public List<string> DoOperateCodeManage(string Number, string codeId)
         {
             List<string> lstResult = iSystemDoc.DoOperateCodeManage(Number, codeId);
             iSystemDoc = null;
             return lstResult;
         }
         #endregion

        #region 附件上传
         public MsDocClass uploadFile(MsDocClass Ms)
         {
             Ms = iSystemDoc.InsertDoc(Ms);
             //iSystemDoc = null;
             return Ms;
         }
        #endregion

        #region 返回 当前人所拥有的文档操作权限权限
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sId">文件夹ID</param>
        /// <returns>00完全共享 ； 01只读共享；05未共享给当前人</returns>
         public string GetShare(string sId)
         {
             string sShare = iSystemDoc.GetShare(sId);
             //iSystemDoc = null;
             return sShare;
         }
        #endregion


         #region 返回文件夹下所有文件与下级文件夹信息
         /// <summary>
         /// 返回文件夹下所有文件与下级文件夹信息
        /// </summary>
        /// <param name="Ms">要查询的文件夹消息对象</param>
        /// <returns>查询结果</returns>
         public DataSet GetFilesMess(MsSecondClass Ms)
         {
             DataSet dSet = iSystemDoc.GetFilesMess(Ms);
             //iSystemDoc = null;
             return dSet;
         }
        #endregion


         /// <summary>
         /// 返回文件类型 图片
         /// </summary>
         /// <param name="sType"></param>
         /// <returns></returns>
         public string GetTypeimage(string sType)
         {
             string sReturn = "";
             #region 返回文件类型
             switch (sType.ToLower())
             {
                 case "":
                     sReturn = "folder_open.gif";
                     break;
                 case "aac":
                     sReturn = "aac.gif";
                     break;
                 case "ace":
                     sReturn = "ace.gif";
                     break;
                 case "ai":
                     sReturn = "ai.gif";
                     break;
                 case "ain":
                     sReturn = "ain.gif";
                     break;
                 case "amr":
                     sReturn = "amr.gif";
                     break;
                 case "app":
                     sReturn = "app.gif";
                     break;
                 case "arj":
                     sReturn = "arj.gif";
                     break;
                 case "asf":
                     sReturn = "asf.gif";
                     break;
                 case "asp":
                     sReturn = "asp.gif";
                     break;
                 case "aspx":
                     sReturn = "aspx.gif";
                     break;
                 case "av":
                     sReturn = "av.gif";
                     break;
                 case "bin":
                     sReturn = "bin.gif";
                     break;
                 case "avi":
                     sReturn = "avi.gif";
                     break;
                 case "bmp":
                     sReturn = "bmp.gif";
                     break;
                 case "cab":
                     sReturn = "cab.gif";
                     break;
                 case "cat":
                     sReturn = "cat.gif";
                     break;
                 case "cdr":
                     sReturn = "cdr.gif";
                     break;
                 case "chm":
                     sReturn = "chm.gif";
                     break;
                 case "com":
                     sReturn = "com.gif";
                     break;
                 case "css":
                     sReturn = "css.gif";
                     break;
                 case "cur":
                     sReturn = "cur.gif";
                     break;
                 case "dat":
                     sReturn = "dat.gif";
                     break;
                 case "dll":
                     sReturn = "dll.gif";
                     break;
                 case "dmv":
                     sReturn = "dmv.gif";
                     break;
                 case "doc":
                     sReturn = "doc.gif";
                     break;
                 case "dot":
                     sReturn = "dot.gif";
                     break;
                 case "dps":
                     sReturn = "dps.gif";
                     break;
                 case "dpt":
                     sReturn = "dpt.gif";
                     break;
                 case "dwg":
                     sReturn = "dwg.gif";
                     break;
                 case "dxf":
                     sReturn = "dxf.gif";
                     break;
                 case "emf":
                     sReturn = "emf.gif";
                     break;
                 case "eps":
                     sReturn = "eps.gif";
                     break;
                 case "et":
                     sReturn = "et.gif";
                     break;
                 case "ett":
                     sReturn = "ett.gif";
                     break;
                 case "exe":
                     sReturn = "exe.gif";
                     break;
                 case "fla":
                     sReturn = "fla.gif";
                     break;
                 case "ftp":
                     sReturn = "ftp.gif";
                     break;
                 case "gif":
                     sReturn = "gif.gif";
                     break;
                 case "hlp":
                     sReturn = "hlp.gif";
                     break;
                 case "htm":
                     sReturn = "htm.gif";
                     break;
                 case "html":
                     sReturn = "html.gif";
                     break;
                 case "icl":
                     sReturn = "icl.gif";
                     break;
                 case "ico":
                     sReturn = "ico.gif";
                     break;
                 case "img":
                     sReturn = "img.gif";
                     break;
                 case "inf":
                     sReturn = "inf.gif";
                     break;
                 case "ini":
                     sReturn = "ini.gif";
                     break;
                 case "iso":
                     sReturn = "iso.gif";
                     break;
                 case "jpeg":
                     sReturn = "jpeg.gif";
                     break;
                 case "jpg":
                     sReturn = "jpg.gif";
                     break;
                 case "js":
                     sReturn = "js.gif";
                     break;
                 case "m3u":
                     sReturn = "m3u.gif";
                     break;
                 case "max":
                     sReturn = "max.gif";
                     break;
                 case "mdb":
                     sReturn = "mdb.gif";
                     break;
                 case "mde":
                     sReturn = "mde.gif";
                     break;
                 case "mht":
                     sReturn = "mht.gif";
                     break;
                 case "mid":
                     sReturn = "mid.gif";
                     break;
                 case "midi":
                     sReturn = "midi.gif";
                     break;
                 case "mov":
                     sReturn = "mov.gif";
                     break;
                 case "mp3":
                     sReturn = "mp3.gif";
                     break;
                 case "mp4":
                     sReturn = "mp4.gif";
                     break;
                 case "mpeg":
                     sReturn = "mpeg.gif";
                     break;
                 case "mpg":
                     sReturn = "mpg.gif";
                     break;
                 case "msi":
                     sReturn = "msi.gif";
                     break;
                 case "nrg":
                     sReturn = "nrg.gif";
                     break;
                 case "ocx":
                     sReturn = "ocx.gif";
                     break;
                 case "ogg":
                     sReturn = "ogg.gif";
                     break;
                 case "ogm":
                     sReturn = "ogm.gif";
                     break;
                 case "pdf":
                     sReturn = "pdf.gif";
                     break;
                 case "png":
                     sReturn = "png.gif";
                     break;
                 case "pot":
                     sReturn = "pot.gif";
                     break;
                 case "ppt":
                     sReturn = "ppt.gif";
                     break;
                 case "psd":
                     sReturn = "psd.gif";
                     break;
                 case "pub":
                     sReturn = "pub.gif";
                     break;
                 case "qt":
                     sReturn = "qt.gif";
                     break;
                 case "ra":
                     sReturn = "ra.gif";
                     break;
                 case "ram":
                     sReturn = "ram.gif";
                     break;
                 case "rar":
                     sReturn = "rar.gif";
                     break;
                 case "rm":
                     sReturn = "rm.gif";
                     break;
                 case "rmvb":
                     sReturn = "rmvb.gif";
                     break;
                 case "rtf":
                     sReturn = "rtf.gif";
                     break;
                 case "swf":
                     sReturn = "swf.gif";
                     break;
                 case "tar":
                     sReturn = "tar.gif";
                     break;
                 case "tif":
                     sReturn = "tif.gif";
                     break;
                 case "tiff":
                     sReturn = "tiff.gif";
                     break;
                 case "txt":
                     sReturn = "txt.gif";
                     break;
                 case "url":
                     sReturn = "url.gif";
                     break;
                 case "vbs":
                     sReturn = "vbs.gif";
                     break;
                 case "vsd":
                     sReturn = "vsd.gif";
                     break;
                 case "vss":
                     sReturn = "vss.gif";
                     break;
                 case "vst":
                     sReturn = "vst.gif";
                     break;
                 case "wav":
                     sReturn = "wav.gif";
                     break;
                 case "wave":
                     sReturn = "wave.gif";
                     break;
                 case "wm":
                     sReturn = "wm.gif";
                     break;
                 case "wma":
                     sReturn = "wma.gif";
                     break;
                 case "wmd":
                     sReturn = "wmd.gif";
                     break;
                 case "wmf":
                     sReturn = "wmf.gif";
                     break;
                 case "wmv":
                     sReturn = "wmv.gif";
                     break;
                 case "wps":
                     sReturn = "wps.gif";
                     break;
                 case "wpt":
                     sReturn = "wpt.gif";
                     break;
                 case "xls":
                     sReturn = "xls.gif";
                     break;
                 case "xlt":
                     sReturn = "xlt.gif";
                     break;
                 case "xml":
                     sReturn = "xml.gif";
                     break;
                 case "zip":
                     sReturn = "zip.gif";
                     break;
                 default:
                     sReturn = "unknown.gif";
                     break;
             }
             #endregion
             return sReturn;
         }

         /// <summary>
         /// 返回文件类型 文字
         /// </summary>
         /// <param name="sType"></param>
         public string GetTypetxt(string sType)
         {
             string sReturn;
             #region 返回文件类型
             switch (sType.ToLower())
             {
                 case "":
                     sReturn = "文件夹";
                     break;
                 case "txt":
                     sReturn = "文本文件";
                     break;
                 case "doc":
                     sReturn = "Word文件";
                     break;
                 case "exe":
                     sReturn = "安装文件";
                     break;
                 case "rar":
                     sReturn = "压缩文件";
                     break;
                 case "zip":
                     sReturn = "压缩文件";
                     break;
                 case "xlsx":
                     sReturn = "Excel文件";
                     break;
                 case "xls":
                     sReturn = "Excel文件";
                     break;
                 case "dll":
                     sReturn = "动态链接文件";
                     break;
                 case "pdf":
                     sReturn = "Adobe文档";
                     break;
                 case "gif":
                     sReturn = "图片文件";
                     break;
                 case "jpg":
                     sReturn = "图片文件";
                     break;
                 case "ICO":
                     sReturn = "位图文件";
                     break;
                 case "bmp":
                     sReturn = "图片文件";
                     break;
                 case "PNG":
                     sReturn = "图片文件";
                     break;
                 case "dxf":
                     sReturn = "CAD文件";
                     break;
                 default:
                     sReturn = "其它文件";
                     break;
             }
             #endregion
             return sReturn;
         }

         public List<MsSecondClass> GetSysDocNodesXMLmanage(string FolderId, string sClassType, string sNodeTab)
         {
             List<MsSecondClass> msList = iSystemDoc.GetSysDocNodesXMLmanage(FolderId, sClassType, sNodeTab);
            // iSystemDoc = null;
             return msList;
         }

         #region 根据条件返回系统文档下边 文件夹集合
         public List<MsSecondClass> GetMsSecondItem(string sWhere)
         {
             List<MsSecondClass> msList =iSystemDoc.GetMsSecondItem(sWhere);
            // iSystemDoc = null;
             return msList;
         }
         #endregion

         #region 根据一级类别编号规则 生成文档编号
         /// <summary>
         /// 根据一级类别编号规则 生成文档编号
         /// </summary>
         /// <param name="sClassType">文档一级类别</param>
         /// <returns>生成的文档编号</returns>
         public string GetEncodRules(string sClassType,string FoldrCode)
         {
             string sRules = iSystemDoc.GetEncodRules(sClassType, FoldrCode);
            // iSystemDoc = null;
             return sRules;
         }
         #endregion

         #region 删除文件
         public bool DelSysDoc(MsDocClass Ms)
         {
             bool bFlag = iSystemDoc.DelSysDoc(Ms);
            // iSystemDoc = null;
             return bFlag;
         }
        #endregion

         #region 复制 剪切
         /// </summary>
         /// <param name="sFiesId">文件ID串 </param>
         /// <param name="sWork">操作类型 Code复制/Shear剪切</param>
         /// <param name="sType">文件类型串 ,号分隔</param>
         /// <param name="sObjectID">要进行 粘贴的文件夹ID</param>
         /// <param name="sClassType">一级栏目类型</param>
         public bool Fiesmove(string sFiesId, string sWork, string sType, string sObjectID, string sClassType)
         {
             bool bFlag = iSystemDoc.Fiesmove(sFiesId, sWork, sType, sObjectID, sClassType);
            // iSystemDoc = null;
             return bFlag;
         }
         #endregion

         #region 文件检索
         /// <summary>
         /// 
         /// </summary>
         /// <param name="sQueryFies">文件查询条件</param>
         /// <param name="sQueryFolder">文件夹查询条件</param>
         /// <returns></returns>
         public DataSet GetFilesSearch(string sQuery)
         {
             DataSet dSet = iSystemDoc.GetFilesSearch(sQuery);
           //  iSystemDoc = null;
             return dSet;
         }
         #endregion

         #region 
         public string GetCodeRuleMes(string sClassType)
         {
             return iSystemDoc.GetCodeRuleMes(sClassType);
         }
        #endregion

        #region 返回文件信息
         public MsDocClass GetDoc(MsDocClass Ms)
         {
             return iSystemDoc.GetDoc(Ms);
         }
        #endregion

        #region 更新文件信息
         public int UpdateDoc(MsDocClass Ms)
         {
             return iSystemDoc.UpdateDoc(Ms);
         }
        #endregion
    }
}
